package com.zjsd.sqeybusiness.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.framework.web.domain.server.Sys;
import com.zjsd.sqeybusiness.dto.*;
import org.drools.core.base.RuleNameEndsWithAgendaFilter;
import org.kie.api.runtime.KieSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
@RequestMapping("/sqeybusiness/drool")
public class TestDroolsController extends BaseController {


    @Resource
    private KieSession kieSession;

    @ResponseBody
    @RequestMapping("/test")
    public void test(){
        /*Address address = new Address();
        address.setPostcode("99425");
        AddressCheckResult result = new AddressCheckResult();
        kieSession.insert(address);
        kieSession.insert(result);
        int ruleFiredCount = kieSession.fireAllRules();
        System.out.println("触发了" + ruleFiredCount + "条规则");

        if(result.isPostCodeResult()){
            System.out.println("规则校验通过");
        }


        String name="张三";
        User user=new User("张三",18);
        kieSession.insert(name);
        kieSession.insert(user);
        kieSession.fireAllRules(new RuleNameEndsWithAgendaFilter("contains"));*/

        ComputeDeductDTO computeDeductDTO = new ComputeDeductDTO();
        computeDeductDTO.setGznx(11);
        computeDeductDTO.setDklx("1");
        computeDeductDTO.setYwlx("1");
        computeDeductDTO.setKtlx("1");
        computeDeductDTO.setDknum(new BigDecimal(3));

        ComputeXseDTO computeXseDTO = new ComputeXseDTO() ;

        computeXseDTO.setXkxse(new BigDecimal(40000));
        computeXseDTO.setXktc(new BigDecimal(5000));


        kieSession.insert(computeDeductDTO);
        int ruleFiredCount = kieSession.fireAllRules();
        System.out.println("触发了" + ruleFiredCount + "条规则");
        System.out.println("提成金额：" + computeDeductDTO.getTcje() + "元");

        kieSession.insert(computeXseDTO);
        int ruleFiredCount1 = kieSession.fireAllRules();
        System.out.println("销售额规则：触发了" + ruleFiredCount + "条规则");
        System.out.println("销售额提成金额：" + computeXseDTO.getXsetc() + "元");

    }
}
